// 路由
import { ref } from "vue";
import { onShow } from "@dcloudio/uni-app";
import { storeToRefs } from "pinia";
import useSafeStore from "@/store/modules/safe.js";
export function useRouterCheck() {
  let safeStore = useSafeStore();
  let { fingerPrint, usePassword,isAuth } = storeToRefs(safeStore);

  let routeChecker = ref(false);
  onShow(() => {
    if (fingerPrint.value || usePassword.value) {
      let pages = getCurrentPages();
      let currentPage = pages[pages.length - 1];
      let route = currentPage.route;
      if (route !== "pages/auth/index" && !isAuth.value) {
        
        // #ifdef H5
        if (usePassword.value) {
        // #endif
        // #ifdef APP-PLUS
        if (fingerPrint.value || usePassword.value) {
        // #endif
        uni.navigateTo({
            url: "/pages/auth/index",
          });
        }
        } else {
          routeChecker.value = true;
      }
      } else {
        routeChecker.value = true;
        
    }
  })
  return { routeChecker };
}